package com.qcby.controller;

import com.qcby.dao.MessageDao;
import com.qcby.entity.Message;
import com.qcby.entity.Result;
import com.qcby.entity.Teacher;
import com.qcby.service.MessageService;
import com.qcby.service.TeacherService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "教师接口")
@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private MessageService messageService;
    @ApiModelProperty(value = "登录接口")
    @PostMapping("/login")
    @ResponseBody
    public Result login(Teacher teacher, HttpServletRequest request){
        System.out.println(teacher);
        return teacherService.login(teacher,request);
    }
    @ApiModelProperty(value = "根据工号查询教师信息")
    @PostMapping("/findByWorkNumber")
    public Result findByWorkNumber(Teacher teacher){
        return Result.success(teacherService.findByWorkNumber(teacher));
    }

    @ApiOperation(value = "查询教师信息")
    @PostMapping("/SearchTeachers")
    @ResponseBody
    public Result SearchTeachers(Teacher teacher) {
        return Result.success(teacherService.SearchTeachers(teacher));
    }

    @ApiOperation(value = "添加教师信息")
    @PostMapping("/AddTeacher")
    @ResponseBody
    public Result AddTeacher(Teacher teacher) {

        return Result.success(teacherService.AddTeacher(teacher));
    }


    @ApiOperation(value = "更新教师信息")
    @PostMapping("/UpdateTeacher")
    @ResponseBody
    public Result UpdateTeacher(Teacher teacher) {

        return Result.success(teacherService.UpdateTeacher(teacher));
    }

    @ApiOperation(value = "删除教师信息")
    @PostMapping("/DeleteTeacher")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id" ,dataType = "Integer")
    })
    public Result DeleteTeacher(Integer id) {

        return Result.success(teacherService.DeleteTeacher(id));
    }


    @ApiOperation(value = "查询班级教师信息")
    @PostMapping("/SearchClassTeacher")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id" ,dataType = "Integer")
    })
    public Result SearchClassTeacher(Integer id) {

        return Result.success(teacherService.SearchClassTeacher(id));
    }
    @GetMapping("/logout")
    public Result logout(HttpServletRequest request) {
        request.getSession().removeAttribute("teacher");
        return Result.success();
    }

}
